package com.ruoyi.web.controller.app;

import com.ruoyi.app.domain.AppHotel;
import com.ruoyi.app.service.IAppHotelService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 酒店Controller
 *
 * @author ruoyi
 * @date 2025-01-12
 */
@RestController
@RequestMapping("/app/hotel")
public class AppHotelController extends BaseController
{
    @Autowired
    private IAppHotelService appHotelService;

    /**
     * 查询酒店列表
     */
    @PreAuthorize("@ss.hasPermi('app:hotel:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppHotel appHotel)
    {
        startPage();
        List<AppHotel> list = appHotelService.selectAppHotelList(appHotel);
        return getDataTable(list);
    }

    /**
     * 导出酒店列表
     */
    @PreAuthorize("@ss.hasPermi('app:hotel:export')")
    @Log(title = "酒店", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppHotel appHotel)
    {
        List<AppHotel> list = appHotelService.selectAppHotelList(appHotel);
        ExcelUtil<AppHotel> util = new ExcelUtil<AppHotel>(AppHotel.class);
        util.exportExcel(response, list, "酒店数据");
    }

    /**
     * 获取酒店详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:hotel:query')")
    @GetMapping(value = "/{hotelId}")
    public AjaxResult getInfo(@PathVariable("hotelId") Long hotelId)
    {
        return success(appHotelService.selectAppHotelByHotelId(hotelId));
    }

    /**
     * 新增酒店
     */
    @PreAuthorize("@ss.hasPermi('app:hotel:add')")
    @Log(title = "酒店", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppHotel appHotel)
    {
        return toAjax(appHotelService.insertAppHotel(appHotel));
    }

    /**
     * 修改酒店
     */
    @PreAuthorize("@ss.hasPermi('app:hotel:edit')")
    @Log(title = "酒店", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppHotel appHotel)
    {
        return toAjax(appHotelService.updateAppHotel(appHotel));
    }

    /**
     * 删除酒店
     */
    @PreAuthorize("@ss.hasPermi('app:hotel:remove')")
    @Log(title = "酒店", businessType = BusinessType.DELETE)
	@DeleteMapping("/{hotelIds}")
    public AjaxResult remove(@PathVariable Long[] hotelIds)
    {
        return toAjax(appHotelService.deleteAppHotelByHotelIds(hotelIds));
    }
}
